package com.day02.array;

import java.util.Random;

/**
 * @Classname ArrayDemo03
 * @Description 双色球
 * @Date 2022/1/11 0:29
 * @Created by 666
 */
public class ArrayDemo03 {

    public static int[] createLuckNumber() {
        int[] numbers = new int[7];
        Random r = new Random();
        for (int i = 0; i < numbers.length - 1; i++) {
            //需要从33个球中选出数据传入数组，必须判断数据是否重复 {22,32,10,12,23,33|44}
            //                                                   i
            while (true) {
                int date = r.nextInt(33) + 1;
                boolean flag = true;// 代表数据不重复
                for (int j = 0; j < i; j++) {
                    if (numbers[j] == date) {
                        System.out.println("相同的数字为："+date);
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    numbers[i] = date;
                    break;
                }
            }
        }
        int blueDate = r.nextInt(16) + 1;
        numbers[numbers.length - 1] = blueDate;
        return numbers;
    }

    public static void main(String[] args) {
        int[] luckNumber = createLuckNumber();
        for (int i = 0; i <luckNumber.length; i++) {
            System.out.print(luckNumber[i]+"\t");
        }
    }
}
